using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;

namespace CMS.BLL
{
    public class AlbumImages
    {
           #region Common
        public eAlbumImages   Data;

        public AlbumImages()
        {
            Data = new eAlbumImages();
		}

        ~AlbumImages()
        {
		}

		public virtual void Dispose()
        {
		}

        public int DeleteById(int ID)
        {
            int nResult = 0;
            cAlbumImages objDAL = new cAlbumImages();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
            cAlbumImages objDAL = new cAlbumImages();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int Insert()
        {
            int nResult = 0;
            cAlbumImages objInfor = new cAlbumImages(); 
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = 1;
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
            cAlbumImages objInfor = new cAlbumImages();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID; 
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

     

        private void MappingData(cAlbumImages objInfor)
        {
            objInfor.ImageName = Data.ImageName;
            objInfor.AlbumID = Data.AlbumID;
        }

        private void ConvertData(cAlbumImages objInfor)
        {
            Data.ImageName = objInfor.ImageName;
            Data.AlbumID = objInfor.AlbumID;

        }

        public DataTable Search(int AlbumID, int PageIndex, int PageSize, ref int PageCount)
        {
            DataTable tbResult = new DataTable();
            cAlbumImages objDAL = new cAlbumImages();
            tbResult = objDAL.Search( AlbumID,  PageIndex,  PageSize, ref  PageCount);
            return tbResult;
        }
        #endregion
    }
}
